package com.yang.moyu.meta.config.service.impl;

import com.yang.moyu.meta.config.mapper.InfOperateLogMapper;
import com.yang.moyu.meta.config.service.InfOperateLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Create by 10296 on 2021/12/15
 *
 * @Description: 操作日志记录类
 */
@Service
public class InfOperateLogServiceImpl implements InfOperateLogService {


    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private InfOperateLogMapper logMapper;

    @Override
    public int saveLog(String infType, String infResult, String requestXml, String responseXml, long startTime, long endTime) {

        long startDate;
        long endDate;
        if (startTime == 0) {
            startDate = System.currentTimeMillis();
        } else {
            startDate = startTime;
        }
        if (endTime == 0) {
            endDate = System.currentTimeMillis();
        } else {
            endDate = endTime;
        }

        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("infType", infType);
        paramsMap.put("infResult", infResult);
        paramsMap.put("requestXml", requestXml);
        paramsMap.put("responseXml", responseXml);
        paramsMap.put("startTime", startDate);
        paramsMap.put("endTime", endDate);
        logger.info(paramsMap + "");
        return logMapper.saveInfLog(paramsMap);
    }
}
